<?
include ("config.php");
session_start();
$r = $_REQUEST['r'];
//this page is invisible, it just creates the login session according to blink.login and directs to the right direction
if ($_REQUEST['user'] && $_REQUEST['pass']){
    $blink = new Blink;
    $ret = $blink->login($_REQUEST['user'],$_REQUEST['pass']);
    if(is_array($ret) && !$ret['error']){
        $_SESSION['id']         = $ret['id'];
        $_SESSION['user']       = $ret['user'];
        $_SESSION['utypeid']    = $ret['utypeid'];
        $_SESSION['levels']     = $ret['levels'];
        
        if(!$r){
            header("Location: index.php");
        }else{
            $row = array("userid"=>$ret['id']);
            $r = $blink->ReplaceKeys($row,$r);
            header("Location: ".$r);
        }
    }else{
        header("Location: error.php?err=".$ret['error']);
    }
}else{
      header("Location: error.php?err=".$ret['error']);
}
?>